
<div class='page-header'>
    当前位置：<span class="text-primary">[{{pagedata.worker.name}}]大夫排班</span>
</div>
<style type="text/css">
    #calendar .header {
        width: 966px;
        height: 40px;
        margin-bottom: 40px;

    }

    #calendar .weeks {
        border-bottom: 1px solid #ccc;
        width: 966px;
        height: 40px;
        line-height: 40px;
        background: #f2f2f2;
    }

    #calendar .weeks .col-sm-2 {
        width: 138px;
        font-weight: bold;
        text-align: center;
    }

    #calendar .dates {
        width: 966px;
        height: 138px;
        text-align: center;

    }

    #calendar .dates .col-sm-2 {
        position: relative;
        width: 138px;
        height: 138px;
        text-align: center;
        background: #fefefe;
        line-height: 130px;
        border: 1px solid #f2f2f2;
    }


    #calendar .dates .col-sm-2 .btn {
        margin: 0;

        color:#fff;
        overflow: hidden;

        -ms-word-break: break-all;
        word-break: break-all;
        word-wrap: break-word;
        white-space:normal;

        max-height:50px;
        background:#f2f2f2;
        color:#333;

    }
    #calendar .dates .col-sm-2 .btn.btn-set-has {
        background: #00aeff;
        color:#fff;
    }
    #calendar .dates .col-sm-2 .date{
        position:absolute;
        right:0;top:5px;
        font-size:14px;
        color:#999;
        line-height:20px;
        display:inline-block;width:20px;height:20px;
    }
    #calendar .dates .col-sm-2 .link{
        position:absolute;
        right:0;bottom:5px;
        font-size:14px;
        color:#666;
        line-height:20px;
        text-align: center;
        display:inline-block;width:138px;height:20px;
    }

    #loading {
        width:100%;
        padding:20px 0;
        text-align: center;;
    }

    #calendar .dates .col-sm-2.select {
        /*background:#fefdeb;*/
    }
    #calendar .dates .col-sm-2 a {
        color:#666;
    }
</style>
<div class="page-content">
<div class="row">
    <div class="col-sm-12">
        <div id="calendar">
            <div class="header">
                <div>  
					<label ng-repeat="(value,dtitle) in pagedata.on_days" class="checkbox-inline" >
						<input type="checkbox"  value="{{value}}" ng-checked="pagedata.worker.on_days.indexOf(';'+value+';')>=0" disabled="true"/> {{dtitle}}
					</label>
                    <span class=" pull-right">
                            <select class="form-control" style="width:100px;display:inline-block;" ng-model="pagedata.currentyear"  id="year">  
                                <option  ng-repeat="y in pagedata.years" value="{{y}}"  ng-select="pagedata.currentyear==y">{{y}}</option>
                            </select>
                                    年
                            <select class="form-control" style="width:100px;display:inline-block;" ng-model="pagedata.currentmonth" id="month"> 
                                <option ng-repeat="m in  pagedata.months" value="{{m}}"  ng-select="pagedata.currentmonth==m" >{{m}}</option>
                            </select>
                                    月
                        </span>
                </div>
               <div class="input-group">
                        <a href="javascript:;" ng-click="pagedata.batch_set()" class="btn btn-default btn-sm btn-batch-set" style="display:inline-block;margin:10px 5px">重置排班</a>
                        <a href="javascript:;" ng-click="pagedata.deletepaiall()" class="btn btn-default btn-sm btn-clear" style="display:inline-block;margin:10px 5px">清空当月</a>
                </div>
            </div>
            <div class="weeks">
                <div class="col-sm-2">日</div>
                <div class="col-sm-2">一</div>
                <div class="col-sm-2">二</div>
                <div class="col-sm-2">三</div>
                <div class="col-sm-2">四</div>
                <div class="col-sm-2">五</div>
                <div class="col-sm-2">六</div>
            </div>
            <div id="loading"><i class="fa fa-spinner fa-spin"></i> 正在加载数据</div>
			<div class="dates">
				<div ng-repeat="item in pagedata.kongday" class="col-sm-2 date-item ">
					<div class="date"></div>
					<a>
						<div>
						空
						</div>
						
					</a>
				</div>
				<div ng-repeat="(k,c) in pagedata.calendar" class="col-sm-2 date-item " ng-class="{'select':c!=null && c!=''}" date="{{k}}" storeid="{{c.storeid}}">
					<div class="date">{{pagedata.d[k]}}</div>
					<div class="link" ng-if="c.storeid>0">
						<a href="javascript:;" ng-click="pagedata.deletepai(k)" class="btn-delete" title="取消"><i class="icon icon-delete"></i></a>
					</div>
					<a href="javascript:;" ng-click="pagedata.selectpai(k)" class="btn btn-set" ng-class="{'btn-set-has':c!='' && c!=null}" >
						<div ng-if="c=='' || c==null">
						排班
						</div>
						<div ng-if="c.storeid>0">
						{{c.title}}
						</div>
						<div ng-if="c.storeid>0">
						{{c.time_hour.start}}~{{c.time_hour.end}}
						</div>
					</a>
				</div>
			</div>
        </div>
    </div>
</div>
</div>
<script language="javascript">
function getDates(){
		scope.get('jy_yiliao/merch.lesson_pai/dates/year='+scope.pagedata.currentyear+'&month='+scope.pagedata.currentmonth,function(res){
			scope.pagedata.week=res.week;
			scope.pagedata.kongday=res.kongday;
			scope.pagedata.calendar=res.calendar;
			scope.pagedata.d=res.d;
			$('#loading').hide();
			scope.$evalAsync();
		});
}
scope.pagedata.selectpai=function(k){
    var onday = k;
	console.log(onday);
	scope.modal_json({'action':'merch.lesson_pai','op':'set','query':'onday='+onday});
}
scope.pagedata.deletepai=function(k){
            var currentDate = k;
			scope.confirm({
				'message':'确认取消 ' + currentDate + " 的排班?",
				'success':function(){
				var params = {
					'plugin':'jy_yiliao',
					'action':'merch.lesson_pai',
					'op':'delete',
					'data': {date: currentDate},						
					}
					scope.post_json(params);
				},
				'fail':function(){}
			});
}
bindHover();
function bindHover(){
        $('.date-item').unbind('mouseover').mouseover(function(){
            if( $(this).attr('storeid')){
                $(this).find('.link').show();
            }else{
                $(this).find('.link').hide();
            }
        }).unbind('mouseout').mouseout(function(){
            $(this).find('.link').hide();

        })
}
$(function(){
    getDates();
    $('#year,#month').change(function(){
            getDates();
    });
})
scope.pagedata.deletepaiall=function(k){
	var year=scope.pagedata.currentyear;
	var month=scope.pagedata.currentmonth;
	scope.confirm({
				'message':'确认要清空 ' + year + "年" + month+"月份的排班吗?",
				'success':function(){
					var params = {
						'plugin':'jy_yiliao',
						'action':'merch.lesson_pai',
						'op':'clear',
						'data': {year: year,month:month},
						'callback':function(ret){
								scope.message('清空成功！');
						}								
					}
					scope.post_json(params);
				}
	});
}
scope.pagedata.batch_set=function(k){
	var year=scope.pagedata.currentyear;
	var month=scope.pagedata.currentmonth;
	scope.modal_json({'action':'merch.lesson_pai','op':'batch_set','query':'year='+year+'&month='+month});   
}
</script>
